﻿using System;
using System.ServiceModel;

namespace VNet.VisiSuite.Common.VNetChannelFactory
{
    /// <summary>
    ///     VNet channel factory
    /// </summary>
    /// <typeparam name="TContract">The type of the contract.</typeparam>
    public class VNetChannelFactory<TContract> : ChannelFactory<TContract>
        where TContract : class
    {
        /// <summary>
        ///     Services the call.
        /// </summary>
        /// <typeparam name="TResponse">The type of the response.</typeparam>
        /// <param name="serviceCall">The service call.</param>
        /// <returns></returns>
        protected virtual TResponse ServiceCall<TResponse>(Func<TContract, TResponse> serviceCall)
        {
            TContract channel = CreateChannel(typeof(TContract).Name);
            return serviceCall(channel);
        }
    }
}